/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.beans;

import com.prefabware.commons.Condition;
import com.prefabware.jmodel.JField;

/**
 * a property of a Java bean consisting of a field, a getter and a setter
 * the field is obligatory, getter and setter may be null
 * @author sisele_job
 *
 */
public class Property {
	private Getter getter;
	private Setter setter;

	public JField getField() {
		return getter.getField();
	}

	public Property(JField field, Getter getter, Setter setter) {
		super();
		Condition.notNull(field, "..field");
		Condition
				.isTrue(setter==null||field.equals(setter.getField()),
						String.format(
								"setter.getField() must point to the given field.actually : setter.getField()=%s , field=%s",
								setter.getField(),field));
		Condition
		.isTrue(getter==null||field.equals(getter.getField()),
				String.format(
						"getter.getField() must point to the given field.actually : getter.getField()=%s , field=%s",
						getter.getField(),field));
		this.getter = getter;
		this.setter = setter;
	}

	public Getter getGetter() {
		return getter;
	}

	public Setter getSetter() {
		return setter;
	}
	public String getName() {
		return this.getField().getName();
	}

	@Override
	public String toString() {
		return "Property [getField()=" + getField() + ", getName()="
				+ getName() + "]";
	}
}
